<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>航运物流用户管理系统</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            font-family: 'Microsoft YaHei', Arial, sans-serif;
            background: linear-gradient(135deg, #1e3c72 0%, #2a5298 50%, #7e8ba3 100%);
            min-height: 100vh;
            display: flex;
            justify-content: center;
            align-items: center;
            padding: 20px;
            position: relative;
            overflow: hidden;
        }

        /* 背景装饰 */
        body::before {
            content: '';
            position: absolute;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            background: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><text y="50" font-size="100" fill="rgba(255,255,255,0.03)">🚢</text></svg>') repeat;
            background-size: 100px 100px;
            animation: float 20s infinite linear;
        }

        @keyframes float {
            0% { transform: translateX(0) translateY(0); }
            50% { transform: translateX(-20px) translateY(-10px); }
            100% { transform: translateX(0) translateY(0); }
        }

        .container {
            background: rgba(255, 255, 255, 0.95);
            border-radius: 20px;
            box-shadow: 0 20px 40px rgba(0, 0, 0, 0.15);
            overflow: hidden;
            width: 100%;
            max-width: 450px;
            position: relative;
            z-index: 1;
            backdrop-filter: blur(10px);
        }

        .header {
            background: linear-gradient(135deg, #1e3c72 0%, #2a5298 100%);
            color: white;
            padding: 30px;
            text-align: center;
            position: relative;
        }

        .header::after {
            content: '🚢';
            position: absolute;
            top: 20px;
            right: 20px;
            font-size: 24px;
            opacity: 0.8;
        }

        .header h1 {
            font-size: 28px;
            margin-bottom: 10px;
            font-weight: 600;
        }

        .header p {
            font-size: 14px;
            opacity: 0.9;
        }

        .toggle-container {
            display: flex;
            background: rgba(30, 60, 114, 0.1);
            border-radius: 25px;
            padding: 4px;
            margin: 20px;
            position: relative;
        }

        .toggle-btn {
            flex: 1;
            padding: 12px;
            border: none;
            background: transparent;
            color: #1e3c72;
            font-size: 16px;
            font-weight: 500;
            cursor: pointer;
            border-radius: 20px;
            transition: all 0.3s ease;
            z-index: 2;
            position: relative;
        }

        .toggle-btn.active {
            color: white;
        }

        .toggle-slider {
            position: absolute;
            top: 4px;
            left: 4px;
            width: calc(50% - 4px);
            height: calc(100% - 8px);
            background: linear-gradient(135deg, #1e3c72 0%, #2a5298 100%);
            border-radius: 20px;
            transition: transform 0.3s ease;
            z-index: 1;
        }

        .toggle-slider.login {
            transform: translateX(100%);
        }

        .form-container {
            padding: 30px;
            display: none;
        }

        .form-container.active {
            display: block;
            animation: fadeIn 0.3s ease;
        }

        @keyframes fadeIn {
            from {
                opacity: 0;
                transform: translateY(10px);
            }
            to {
                opacity: 1;
                transform: translateY(0);
            }
        }

        .form-group {
            margin-bottom: 20px;
        }

        .form-group label {
            display: block;
            margin-bottom: 8px;
            font-weight: 500;
            font-size: 14px;
            color: #1e3c72;
        }

        .input-wrapper {
            position: relative;
        }

        .input-icon {
            position: absolute;
            left: 15px;
            top: 50%;
            transform: translateY(-50%);
            color: #2a5298;
            font-size: 16px;
        }

        .form-group input {
            width: 100%;
            padding: 12px 15px 12px 45px;
            border: 2px solid #e1e8f0;
            border-radius: 10px;
            font-size: 16px;
            transition: all 0.3s ease;
            background: #f8fafc;
        }

        .form-group input:focus {
            outline: none;
            border-color: #2a5298;
            box-shadow: 0 0 0 3px rgba(42, 82, 152, 0.1);
            background: white;
        }

        .btn {
            width: 100%;
            padding: 14px;
            border: none;
            border-radius: 10px;
            font-size: 16px;
            font-weight: 600;
            cursor: pointer;
            transition: all 0.3s ease;
            margin-top: 10px;
            background: linear-gradient(135deg, #1e3c72 0%, #2a5298 100%);
            color: white;
            position: relative;
            overflow: hidden;
        }

        .btn:hover {
            transform: translateY(-2px);
            box-shadow: 0 8px 20px rgba(30, 60, 114, 0.3);
        }

        .btn:active {
            transform: translateY(0);
        }

        .message {
            padding: 12px;
            border-radius: 8px;
            margin-top: 15px;
            text-align: center;
            font-size: 14px;
            display: none;
            animation: slideIn 0.3s ease;
        }

        @keyframes slideIn {
            from {
                opacity: 0;
                transform: translateY(-10px);
            }
            to {
                opacity: 1;
                transform: translateY(0);
            }
        }

        .message.success {
            background: #d4edda;
            color: #155724;
            border: 1px solid #c3e6cb;
        }

        .message.error {
            background: #f8d7da;
            color: #721c24;
            border: 1px solid #f5c6cb;
        }

        .loading {
            display: none;
            text-align: center;
            margin-top: 15px;
        }

        .loading::after {
            content: '';
            display: inline-block;
            width: 20px;
            height: 20px;
            border: 2px solid #f3f3f3;
            border-top: 2px solid #1e3c72;
            border-radius: 50%;
            animation: spin 1s linear infinite;
        }

        @keyframes spin {
            0% { transform: rotate(0deg); }
            100% { transform: rotate(360deg); }
        }

        .info-box {
            background: rgba(30, 60, 114, 0.05);
            border-left: 4px solid #2a5298;
            padding: 15px;
            margin-bottom: 20px;
            border-radius: 5px;
            font-size: 13px;
            color: #1e3c72;
        }

        .footer {
            text-align: center;
            padding: 20px;
            background: rgba(30, 60, 114, 0.05);
            color: #1e3c72;
            font-size: 12px;
            border-top: 1px solid rgba(30, 60, 114, 0.1);
        }

        @media (max-width: 480px) {
            .container {
                margin: 10px;
                max-width: 100%;
            }

            .header {
                padding: 20px;
            }

            .header h1 {
                font-size: 24px;
            }

            .form-container {
                padding: 20px;
            }
        }
    </style>
</head>
<body>
    <div class="container">
        <div class="header">
            <h1>航运物流管理系统</h1>
            <p>基于区块链技术的安全物流平台</p>
        </div>

        <div class="toggle-container">
            <div class="toggle-slider" id="toggleSlider"></div>
            <button class="toggle-btn active" id="registerToggle" onclick="switchForm('register')">
                用户注册
            </button>
            <button class="toggle-btn" id="loginToggle" onclick="switchForm('login')">
                身份验证
            </button>
        </div>

        <!-- 注册表单 -->
        <div class="form-container active" id="registerForm">
            <div class="info-box">
                📋 注册新账户以访问航运物流管理系统，享受基于区块链的安全服务
            </div>
            <form id="registerFormElement">
                <div class="form-group">
                    <label for="regUsername">用户名</label>
                    <div class="input-wrapper">
                        <span class="input-icon">👤</span>
                        <input type="text" id="regUsername" name="username" required placeholder="请输入用户名">
                    </div>
                </div>
                <div class="form-group">
                    <label for="regPassword">密码</label>
                    <div class="input-wrapper">
                        <span class="input-icon">🔒</span>
                        <input type="password" id="regPassword" name="password" required placeholder="请输入密码">
                    </div>
                </div>
                <button type="submit" class="btn">注册账户</button>
                <div id="registerMessage" class="message"></div>
                <div id="registerLoading" class="loading"></div>
            </form>
        </div>

        <!-- 登录验证表单 -->
        <div class="form-container" id="loginForm">
            <div class="info-box">
                🔐 验证您的身份以访问航运物流系统的各项功能
            </div>
            <form id="loginFormElement">
                <div class="form-group">
                    <label for="loginId">用户ID</label>
                    <div class="input-wrapper">
                        <span class="input-icon">🆔</span>
                        <input type="number" id="loginId" name="id" required placeholder="请输入用户ID">
                    </div>
                </div>
                <div class="form-group">
                    <label for="loginPassword">密码</label>
                    <div class="input-wrapper">
                        <span class="input-icon">🔑</span>
                        <input type="password" id="loginPassword" name="password" required placeholder="请输入密码">
                    </div>
                </div>
                <button type="submit" class="btn">验证身份</button>
                <div id="loginMessage" class="message"></div>
                <div id="loginLoading" class="loading"></div>
            </form>
        </div>

        <div class="footer">
            🚢 区块链航运物流管理系统 © 2024
        </div>
    </div>

    <script>
        // API基础URL
        const API_BASE_URL = 'http://172.21.136.66:8080/user';

        // 切换表单
        function switchForm(type) {
            const registerForm = document.getElementById('registerForm');
            const loginForm = document.getElementById('loginForm');
            const registerToggle = document.getElementById('registerToggle');
            const loginToggle = document.getElementById('loginToggle');
            const toggleSlider = document.getElementById('toggleSlider');

            if (type === 'register') {
                registerForm.classList.add('active');
                loginForm.classList.remove('active');
                registerToggle.classList.add('active');
                loginToggle.classList.remove('active');
                toggleSlider.classList.remove('login');
            } else {
                registerForm.classList.remove('active');
                loginForm.classList.add('active');
                registerToggle.classList.remove('active');
                loginToggle.classList.add('active');
                toggleSlider.classList.add('login');
            }
        }

        // 显示消息
        function showMessage(elementId, message, isSuccess) {
            const messageElement = document.getElementById(elementId);
            messageElement.textContent = message;
            messageElement.className = `message ${isSuccess ? 'success' : 'error'}`;
            messageElement.style.display = 'block';
            
            // 3秒后自动隐藏
            setTimeout(() => {
                messageElement.style.display = 'none';
            }, 3000);
        }

        // 显示/隐藏加载状态
        function setLoading(elementId, show) {
            const loadingElement = document.getElementById(elementId);
            loadingElement.style.display = show ? 'block' : 'none';
        }

        // 注册表单处理
        document.getElementById('registerFormElement').addEventListener('submit', async function(e) {
            e.preventDefault();
            
            const username = document.getElementById('regUsername').value;
            const password = document.getElementById('regPassword').value;
            
            setLoading('registerLoading', true);
            
            try {
                const response = await fetch(`${API_BASE_URL}/add`, {
                    method: 'POST',
                    headers: {
                        'Content-Type': 'application/x-www-form-urlencoded',
                    },
                    body: `username=${encodeURIComponent(username)}&passwd=${encodeURIComponent(password)}`
                });
                
                const result = await response.json();
                
                if (result.code === "0") {
                    showMessage('registerMessage', '🎉 注册成功！欢迎使用航运物流系统', true);
                    this.reset();
                    // 2秒后自动切换到登录页面
                    setTimeout(() => {
                        switchForm('login');
                    }, 2000);
                } else {
                    showMessage('registerMessage', result.message || '❌ 注册失败，请重试', false);
                }
            } catch (error) {
                console.error('注册错误:', error);
                showMessage('registerMessage', '🌐 网络错误，请检查连接', false);
            } finally {
                setLoading('registerLoading', false);
            }
        });

        // 登录验证表单处理
        document.getElementById('loginFormElement').addEventListener('submit', async function(e) {
            e.preventDefault();
            
            const id = document.getElementById('loginId').value;
            const password = document.getElementById('loginPassword').value;
            
            setLoading('loginLoading', true);
            
            try {
                const response = await fetch(`${API_BASE_URL}/check`, {
                    method: 'POST',
                    headers: {
                        'Content-Type': 'application/x-www-form-urlencoded',
                    },
                    body: `id=${encodeURIComponent(id)}&passwd=${encodeURIComponent(password)}`
                });
                
                const result = await response.json();
                
                if (result.code === "0") {
                    showMessage('loginMessage', '✅ 验证成功！欢迎进入航运物流系统', true);
                    // 这里可以添加登录成功后的跳转逻辑
                    setTimeout(() => {
                        // window.location.href = 'dashboard.html';
                        console.log('登录成功，准备跳转到主界面');
                    }, 2000);
                } else {
                    showMessage('loginMessage', result.message || '❌ 验证失败，用户ID或密码错误', false);
                }
            } catch (error) {
                console.error('验证错误:', error);
                showMessage('loginMessage', '🌐 网络错误，请检查连接', false);
            } finally {
                setLoading('loginLoading', false);
            }
        });

        // 输入框焦点效果
        document.querySelectorAll('input').forEach(input => {
            input.addEventListener('focus', function() {
                this.parentElement.style.transform = 'scale(1.02)';
            });
            
            input.addEventListener('blur', function() {
                this.parentElement.style.transform = 'scale(1)';
            });
        });

        // 添加回车键切换功能
        document.getElementById('regPassword').addEventListener('keypress', function(e) {
            if (e.key === 'Enter') {
                document.getElementById('registerFormElement').dispatchEvent(new Event('submit'));
            }
        });

        document.getElementById('loginPassword').addEventListener('keypress', function(e) {
            if (e.key === 'Enter') {
                document.getElementById('loginFormElement').dispatchEvent(new Event('submit'));
            }
        });
    </script>
</body>
</html>